package com.meisupic.copyright.service.impl;

import static com.meisupic.copyright.common.Constants.DECLARATION_FILE_PATH;
import static com.meisupic.copyright.common.Constants.PUBLISH_STATUS_UNPUBLISHED;
import static com.meisupic.copyright.common.Constants.RIGHT_OWN_MODE_COOPERATION_WORKS;
import static com.meisupic.copyright.common.Constants.RIGHT_OWN_MODE_LEGAL_WORKS;
import static com.meisupic.copyright.common.Constants.RIGHT_OWN_MODE_PERSONAL_WORKS;

import com.itextpdf.text.Chunk;
import com.itextpdf.text.Document;
import com.itextpdf.text.Element;
import com.itextpdf.text.Font;
import com.itextpdf.text.PageSize;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.BaseFont;
import com.itextpdf.text.pdf.PdfWriter;
import com.meisupic.copyright.domain.po.CopyRightWorks;
import com.meisupic.copyright.domain.po.RealNameAuth;
import com.meisupic.copyright.exception.BizException;
import com.meisupic.copyright.service.IDeclarationFilesService;
import com.meisupic.copyright.service.IOssService;
import com.meisupic.copyright.service.IRealNameAuthService;
import com.meisupic.copyright.util.DateUtil;
import com.meisupic.copyright.util.DictionaryUtil;
import com.meisupic.copyright.util.StringUtil;
import java.io.File;
import java.io.IOException;
import java.util.Date;
import org.apache.commons.io.FileUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * creation wuxun
 *
 * @version V1.0
 * @Description: 生产作品创作声明
 * @date 2018/1/20 7:55
 */
@Service
public class DeclarationFilesServiceImpl implements IDeclarationFilesService {

  @Autowired
  private IOssService ossService;

  @Autowired
  private IRealNameAuthService realNameAuthService;

  Logger logger = LoggerFactory.getLogger(this.getClass());

  /**
   * 生成声明文件
   */
  @Override
  public void generateFiles(CopyRightWorks copyRightWorks, String creativePurpose) {

    generateCreateStatement(copyRightWorks, creativePurpose);
    if (RIGHT_OWN_MODE_COOPERATION_WORKS == copyRightWorks.getRightOwnMode()) {
      //合作作品
      generateCooperativeCreationStatement(copyRightWorks);
    } else if (RIGHT_OWN_MODE_LEGAL_WORKS == copyRightWorks.getRightOwnMode()) {
      //法人作品
      generateCorporateWorkStatement(copyRightWorks);
    } else if (RIGHT_OWN_MODE_PERSONAL_WORKS == copyRightWorks.getRightOwnMode()) {
      generateOriginalStatement(copyRightWorks);
    }


  }

  @Override
  public void generateFiles(String creativePurpose, String creativeProcess, String creative,
      String publishStatus, String author, String fileName) {
    // 设置纸张大小
    Document document = new Document(PageSize.A4);
    // 建立一个书写器，与document对象关联
    File file = new File(FileUtils.getUserDirectory(), fileName);
    try {
      PdfWriter.getInstance(document, FileUtils.openOutputStream(file));
      document.open();
      // 设置中文字体
      BaseFont bfChinese = BaseFont
          .createFont("STSongStd-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
      // 标题字体风格
      Font titleFont = new Font(bfChinese, 22, Font.BOLD);

      Font subTitleFont = new Font(bfChinese, 14, Font.BOLD);
      // 正文字体风格
      Font contextFont = new Font(bfChinese, 14, Font.NORMAL);
      // 参数字体风格
      Font paramFont = new Font(bfChinese, 14, Font.UNDERLINE);
      Paragraph title = new Paragraph("作品创作声明\n\n", titleFont);
      // 设置标题格式对齐方式
      title.setAlignment(Element.ALIGN_CENTER);
      title.setLeading(15f);
      document.add(title);
      // 今天日期
      Chunk currentdate = new Chunk(DateUtil.formatDate(new Date()), paramFont);
      String paraName = author.replaceAll("\\$", ",");
      Chunk name = new Chunk(paraName, paramFont);
      // 空段落
      Paragraph emptyPara = new Paragraph("");
      emptyPara.setFirstLineIndent(30);
      document.add(emptyPara);
      // 段落1
      Paragraph para1 = new Paragraph();
      para1.setAlignment(Element.ALIGN_LEFT);
      para1.setFont(contextFont);
      para1.setLeading(20f);
      para1.setSpacingBefore(3);
      para1.add(new Chunk("一、创作目的\n", subTitleFont));
      para1.add(creativePurpose);

      document.add(para1);
      document.add(emptyPara);
      // 段落2
      Paragraph para2 = new Paragraph();
      para2.setAlignment(Element.ALIGN_LEFT);
      para2.setFont(contextFont);
      para2.setLeading(20f);
      para2.setSpacingBefore(3);
      para2.add(new Chunk("二、创作过程\n", subTitleFont));
      para2.add(creativeProcess);
      document.add(para2);
      document.add(emptyPara);
      // 段落3
      Paragraph para3 = new Paragraph();
      para3.setAlignment(Element.ALIGN_LEFT);
      para3.setFont(contextFont);
      para3.setLeading(20f);
      para3.setSpacingBefore(3);
      para3.add(new Chunk("三、作品独创性\n", subTitleFont));
      para3.add(creative);
      document.add(para3);
      document.add(emptyPara);

      // 段落4
      Paragraph para4 = new Paragraph();
      para4.setAlignment(Element.ALIGN_LEFT);
      para4.setFont(contextFont);
      para4.setLeading(20f);
      para4.setSpacingBefore(3);
      para4.add(new Chunk("四、发表情况\n", subTitleFont));
      para4.add(publishStatus);
      para4.add("本人（单位）保证所申请登记的如下作品（制品）的权利归本人（单位）所有，保证提交的文件真实、合法。如有不实，本人愿承担一切法律责任。");
      document.add(para4);
      document.add(emptyPara);
      // 段落5
      Paragraph para5 = new Paragraph();
      para5.setAlignment(Element.ALIGN_LEFT);
      para5.setFont(contextFont);
      para5.setSpacingBefore(3);
      para5.setLeading(20f);
      para5.add("特此说明。");
      document.add(para5);
      // 段落6
      Paragraph para6 = new Paragraph("\n");
      para6.setAlignment(Element.ALIGN_RIGHT);
      para6.setFont(contextFont);
      para6.setSpacingBefore(20);
      para6.setSpacingAfter(0);
      para6.setIndentationRight(10);
      para6.setLeading(10f);
      para6.add("申请人：");
      para6.add(name);
      document.add(para6);
      // 段落7
      Paragraph para7 = new Paragraph("\n");
      para7.setAlignment(Element.ALIGN_RIGHT);
      para7.setFont(contextFont);
      para7.setSpacingBefore(20);
      para7.setSpacingAfter(0);
      para7.setIndentationRight(10);
      para7.setLeading(10f);
      para7.add("日期：");
      para7.add(currentdate);
      document.add(para7);
      document.add(emptyPara);
      document.close();
    } catch (Exception e) {
      logger.error("生成合作声明文件失败", e);
      throw new BizException("生成合作声明文件失败");
    }
    uploadToOSS(file);
  }

  /**
   * 生成作品原创声明
   */
  private void generateOriginalStatement(CopyRightWorks copyRightWorks) {
    // 设置纸张大小
    Document document = new Document(PageSize.A4);
    // 建立一个书写器，与document对象关联
    File file = new File(FileUtils.getUserDirectory(), copyRightWorks.getOriginalStatement());
    try {
      PdfWriter.getInstance(document, FileUtils.openOutputStream(file));
      document.open();
      // 设置中文字体
      BaseFont bfChinese = BaseFont
          .createFont("STSongStd-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
      // 标题字体风格
      Font titleFont = new Font(bfChinese, 22, Font.BOLD);
      // 正文字体风格
      Font contextFont = new Font(bfChinese, 14, Font.NORMAL);
      // 参数字体风格
      Font paramFont = new Font(bfChinese, 14, Font.UNDERLINE);
      Paragraph title = new Paragraph("原创声明", titleFont);
      // 设置标题格式对齐方式
      title.setAlignment(Element.ALIGN_CENTER);
      title.setLeading(15f);
      document.add(title);

      // 作品名称
      Chunk workname = new Chunk(copyRightWorks.getWorksFullName(), paramFont);
      // 作者
      String paraName = copyRightWorks.getAuthor().replaceAll("\\$", ",");
      Chunk name = new Chunk(paraName, paramFont);
      // 创作完成地点
      String createCountry =
          copyRightWorks.getCreationCountry() == null ? "" : copyRightWorks.getCreationCountry();
      String createProvince =
          copyRightWorks.getCreationProvince() == null ? "" : copyRightWorks.getCreationProvince();
      String createCity =
          copyRightWorks.getCreationCity() == null ? "" : copyRightWorks.getCreationCity();
      Chunk completePlace = new Chunk(createCountry + createProvince + createCity, paramFont);
      // 今天日期
      Chunk currentdate = new Chunk(DateUtil.formatDate(new Date()), paramFont);
      String worksTypeName = DictionaryUtil
          .getDicNameByValue(copyRightWorks.getWorksType(), "worktype");
      ;
      // 段落1
      Paragraph para1 = new Paragraph("本人" + name + "提交的作品(作品类型：" + worksTypeName + ")《",
          contextFont);
      para1.setLeading(20f);
      para1.setAlignment(Element.ALIGN_LEFT);
      para1.setSpacingBefore(3);
      para1.setFirstLineIndent(30);
      para1.add(workname);
      para1.add("》系本人独立创作，该作品的原始著作者权归本人" + name +
          " 所有，绝对不侵犯任何第三方权利，在此保证以上声明内容及提交的相关文件真实、合法。如有不实，本人愿承担一切法律责任。");

      document.add(new Paragraph("\n"));
      document.add(para1);
      // 段落2
      Paragraph para2 = new Paragraph("本人依法享有和承担由此作品而产生的权利和全部法律责任。", contextFont);
      para2.setAlignment(Element.ALIGN_LEFT);
      para2.setSpacingBefore(3);
      para2.setFirstLineIndent(30);
      para2.setLeading(20f);
      document.add(para2);

      // 段落5
      Paragraph para5 = new Paragraph();
      para5.setAlignment(Element.ALIGN_LEFT);
      para5.setFont(contextFont);
      para5.setSpacingBefore(3);
      para5.setFirstLineIndent(30);
      para5.setLeading(20f);
      para5.add("特此说明。");
      document.add(para5);
      // 段落6
      Paragraph para6 = new Paragraph("\n");
      para6.setAlignment(Element.ALIGN_RIGHT);
      para6.setFont(contextFont);
      para6.setSpacingBefore(20);
      para6.setSpacingAfter(0);
      para6.setIndentationRight(10);
      para6.setLeading(10f);
      para6.add("签章：");
      para6.add(name);
      document.add(para6);
      // 段落7
      Paragraph para7 = new Paragraph("\n");
      para7.setFont(contextFont);
      para7.setSpacingBefore(20);
      para7.setIndentationRight(10);
      para7.setAlignment(Element.ALIGN_RIGHT);
      para7.setLeading(10f);
      para7.add("日期：");
      para7.add(currentdate);
      document.add(para7);
      document.close();
    } catch (Exception e) {
      logger.error("生成原创声明文件失败", e);
      throw new BizException("生成原创声明文件失败");
    }
    uploadToOSS(file);
  }

  private void uploadToOSS(File file) {
    ossService.putObject(DECLARATION_FILE_PATH + file.getName(), file);
    try {
      FileUtils.forceDelete(file);
    } catch (IOException e) {
      logger.error("刪除声明文件失败", e);
    }
  }

  /**
   * 生成作品创作声明
   */
  private void generateCreateStatement(CopyRightWorks copyRightWorks, String creativePurpose) {
    // 设置纸张大小
    Document document = new Document(PageSize.A4);
    // 建立一个书写器，与document对象关联
    File file = new File(FileUtils.getUserDirectory(), copyRightWorks.getCreativeStatement());
    try {
      PdfWriter.getInstance(document, FileUtils.openOutputStream(file));
      document.open();
      // 设置中文字体
      BaseFont bfChinese = BaseFont
          .createFont("STSongStd-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
      // 标题字体风格
      Font titleFont = new Font(bfChinese, 22, Font.BOLD);

      Font subTitleFont = new Font(bfChinese, 14, Font.BOLD);
      // 正文字体风格
      Font contextFont = new Font(bfChinese, 14, Font.NORMAL);
      // 参数字体风格
      Font paramFont = new Font(bfChinese, 14, Font.UNDERLINE);
      Paragraph title = new Paragraph("作品创作声明\n\n", titleFont);
      // 设置标题格式对齐方式
      title.setAlignment(Element.ALIGN_CENTER);
      title.setLeading(15f);
      document.add(title);
      // 特殊字段设置
      // 作品名称
      Chunk workname = new Chunk(copyRightWorks.getWorksFullName(), paramFont);
      // 作者
      String paraName = copyRightWorks.getAuthor().replaceAll("\\$", ",");

      Chunk name = new Chunk(paraName, paramFont);
      // 年月日
      Chunk creationDate = new Chunk(DateUtil.formatDate(copyRightWorks.getCreationDate()),
          paramFont);

      // 作品特点
      Chunk mainfeatures = new Chunk(copyRightWorks.getMainFeatures(), paramFont);
      // 创作完成地点
      String createCountry =
          copyRightWorks.getCreationCountry() == null ? "" : copyRightWorks.getCreationCountry();
      String createProvince =
          copyRightWorks.getCreationProvince() == null ? "" : copyRightWorks.getCreationProvince();
      String createCity =
          copyRightWorks.getCreationCity() == null ? "" : copyRightWorks.getCreationCity();
      Chunk completePlace = new Chunk(createCountry + createProvince + createCity, paramFont);
      // 今天日期
      Chunk currentdate = new Chunk(DateUtil.formatDate(new Date()), paramFont);

      // 空段落
      Paragraph emptyPara = new Paragraph("");
      emptyPara.setFirstLineIndent(30);
      document.add(emptyPara);
      // 段落1
      Paragraph para1 = new Paragraph();
      para1.setAlignment(Element.ALIGN_LEFT);
      para1.setFont(contextFont);
      para1.setLeading(20f);
      para1.setSpacingBefore(3);
      para1.add(new Chunk("一、创作目的\n", subTitleFont));
      if ("artProductRegist".equals(copyRightWorks.getWorksType())) {
        if (StringUtil.isEmpty(creativePurpose)) {
          para1.add("全方位展示创作人眼中的设计美感和对生活的理解，博得潜在美术作品消费人群的关注。");
        } else {
          para1.add(creativePurpose);
        }
      } else if ("photoProductRegist".equals(copyRightWorks.getWorksType())) {
        para1.add("从摄影师视角来理解拍摄对象，运用构图和摄影手法，展示被拍摄对象的艺术美感，从而将美好的艺术形象留存在画面中。");
      } else if ("chartProductRegist".equals(copyRightWorks.getWorksType())) {
        para1.add("表达的产品构造、性能，为产品的制作与施工、使用与维护提供准确详细的标准和依据。");
      }

      document.add(para1);
      document.add(emptyPara);
      // 段落2
      Paragraph para2 = new Paragraph();
      para2.setAlignment(Element.ALIGN_LEFT);
      para2.setFont(contextFont);
      para2.setLeading(20f);
      para2.setSpacingBefore(3);
      para2.add(new Chunk("二、创作过程\n", subTitleFont));
      para2.add("作品 " + workname + "  ，于 " + creationDate + "  在" + completePlace + "独立创作完成。");
      document.add(para2);
      document.add(emptyPara);
      // 段落3
      Paragraph para3 = new Paragraph();
      para3.setAlignment(Element.ALIGN_LEFT);
      para3.setFont(contextFont);
      para3.setLeading(20f);
      para3.setSpacingBefore(3);
      para3.add(new Chunk("三、作品独创性\n", subTitleFont));
      para3.add(mainfeatures);
      document.add(para3);
      document.add(emptyPara);

      // 段落4
      Paragraph para4 = new Paragraph();
      para4.setAlignment(Element.ALIGN_LEFT);
      para4.setFont(contextFont);
      para4.setLeading(20f);
      para4.setSpacingBefore(3);
      para4.add(new Chunk("四、发表情况\n", subTitleFont));
      if (PUBLISH_STATUS_UNPUBLISHED == copyRightWorks.getPublishStatus()) {
        if (copyRightWorks.getDisplay()) {
          para4
              .add("该作品于" + DateUtil.formatDate(copyRightWorks.getFirstPublishDate())
                  + " 在北京发表\n\n");
        }
      } else {
        Chunk publishdate = new Chunk(DateUtil.formatDate(copyRightWorks.getFirstPublishDate()),
            paramFont);
        Chunk publishCity = new Chunk(copyRightWorks.getFirstPublishCity(), paramFont);
        para4.add("该作品于" + publishdate + " 在" + publishCity + "发表\n\n");
      }
      para4.add("本人（单位）保证所申请登记的如下作品（制品）的权利归本人（单位）所有，保证提交的文件真实、合法。如有不实，本人愿承担一切法律责任。");
      document.add(para4);
      document.add(emptyPara);
      // 段落5
      Paragraph para5 = new Paragraph();
      para5.setAlignment(Element.ALIGN_LEFT);
      para5.setFont(contextFont);
      para5.setSpacingBefore(3);
      para5.setLeading(20f);
      para5.add("特此说明。");
      document.add(para5);
      // 段落6
      Paragraph para6 = new Paragraph("\n");
      para6.setAlignment(Element.ALIGN_RIGHT);
      para6.setFont(contextFont);
      para6.setSpacingBefore(20);
      para6.setSpacingAfter(0);
      para6.setIndentationRight(10);
      para6.setLeading(10f);
      para6.add("申请人：");
      para6.add(name);
      document.add(para6);
      // 段落7
      Paragraph para7 = new Paragraph("\n");
      para7.setAlignment(Element.ALIGN_RIGHT);
      para7.setFont(contextFont);
      para7.setSpacingBefore(20);
      para7.setSpacingAfter(0);
      para7.setIndentationRight(10);
      para7.setLeading(10f);
      para7.add("日期：");
      para7.add(currentdate);
      document.add(para7);
      document.add(emptyPara);
      document.close();
    } catch (Exception e) {
      logger.error("生成合作声明文件失败", e);
      throw new BizException("生成合作声明文件失败");
    }
    uploadToOSS(file);
  }

  /**
   * 法人作品创作声明
   */
  public void generateCorporateWorkStatement(CopyRightWorks copyRightWorks) {
    // 设置纸张大小
    Document document = new Document(PageSize.A4);
    // 建立一个书写器，与document对象关联
    File file = new File(FileUtils.getUserDirectory(), copyRightWorks.getLegalCreationStatement());
    try {
      PdfWriter.getInstance(document, FileUtils.openOutputStream(file));
      document.open();
      // 设置中文字体
      BaseFont bfChinese = BaseFont
          .createFont("STSongStd-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
      // 标题字体风格
      Font titleFont = new Font(bfChinese, 22, Font.BOLD);
      // 正文字体风格
      Font contextFont = new Font(bfChinese, 14, Font.NORMAL);
      // 参数字体风格
      Font paramFont = new Font(bfChinese, 14, Font.UNDERLINE);
      Paragraph title = new Paragraph("法人作品创作声明", titleFont);
      // 设置标题格式对齐方式
      title.setAlignment(Element.ALIGN_CENTER);
      title.setLeading(15f);
      document.add(title);
      // 特殊字段设置
      // 作品名称
      Chunk workname = new Chunk(copyRightWorks.getWorksFullName(), paramFont);
      // 法人名称
      RealNameAuth realNameAuth = realNameAuthService.findByUserId(copyRightWorks.getCreatorId());
      Chunk name = new Chunk(realNameAuth.getLegalName(), paramFont);
      // 年月日
      Chunk currentdate = new Chunk(DateUtil.formatDate(new Date()), paramFont);
      // 空段落
      Paragraph emptyPara = new Paragraph("");
      emptyPara.setLeading(20f);
      emptyPara.setAlignment(Element.ALIGN_LEFT);
      emptyPara.setFont(contextFont);
      emptyPara.setSpacingBefore(3);
      emptyPara.setFirstLineIndent(40);
      document.add(emptyPara);
      document.add(emptyPara);
      document.add(emptyPara);
      // 段落1
      Paragraph para1 = new Paragraph("作品");
      para1.setLeading(20f);
      para1.setAlignment(Element.ALIGN_LEFT);
      para1.setFont(contextFont);
      para1.setSpacingBefore(3);
      para1.setFirstLineIndent(30);
      para1.add(workname);
      para1.add("是");
      para1.add(name);
      para1.add("组织内部员工共同完成，属法人作品，代表法人意志。");
      document.add(para1);
      document.add(emptyPara);
      // 段落2
      Paragraph para2 = new Paragraph(name);
      para2.setAlignment(Element.ALIGN_LEFT);
      para2.setFont(contextFont);
      para2.setSpacingBefore(3);
      para2.setFirstLineIndent(30);
      para2.setLeading(20f);
      para2.add(name + "对此作品承担一切法律责任，作品");
      para2.add(workname);
      para2.add("的著作权归");
      para2.add(name);
      para2.add("所有。");
      document.add(para2);
      document.add(emptyPara);

      Paragraph para2_1 = new Paragraph(name);
      para2_1.setAlignment(Element.ALIGN_LEFT);
      para2_1.setFont(contextFont);
      para2_1.setSpacingBefore(3);
      para2_1.setFirstLineIndent(30);
      para2_1.setLeading(20f);
      para2_1.add("我公司 " + name + " 保证所提交的文件材料真实、合法；并承担一切法律责任。");
      document.add(para2_1);
      document.add(emptyPara);
      // 段落3
      Paragraph para3 = new Paragraph("特此证明。");
      para3.setAlignment(Element.ALIGN_LEFT);
      para3.setFont(contextFont);
      para3.setSpacingBefore(3);
      para3.setFirstLineIndent(40);
      para3.setLeading(20f);
      document.add(para3);
      document.add(emptyPara);
      // 段落4
      Paragraph para4 = new Paragraph();
      para4.setAlignment(Element.ALIGN_RIGHT);
      para4.setFont(contextFont);
      para4.setSpacingBefore(20);
      para4.setSpacingAfter(0);
      para4.setIndentationRight(10);
      para4.add("法人：");
      para4.add(name);
      document.add(para4);
      document.add(emptyPara);
      // 段落3
      Paragraph para5 = new Paragraph();
      para5.setAlignment(Element.ALIGN_RIGHT);
      para5.setFont(contextFont);
      para5.setSpacingBefore(20);
      para5.setSpacingAfter(0);
      para5.setIndentationRight(10);
      para5.add("日期：");
      para5.add(currentdate);
      document.add(para5);
      document.add(emptyPara);
      document.close();
    } catch (Exception e) {
      logger.error("创建法人声明文件失败", e);
      throw new BizException("创建法人声明文件失败");
    }
    uploadToOSS(file);
  }

  /**
   * 合作创作声明
   */
  public void generateCooperativeCreationStatement(CopyRightWorks copyRightWorks) {
    File file = new File(FileUtils.getUserDirectory(), copyRightWorks.getCooperationStatement());
    try {
      // 设置纸张大小
      Document document = new Document(PageSize.A4);
      // 建立一个书写器，与document对象关联
      PdfWriter.getInstance(document, FileUtils.openOutputStream(file));
      document.open();
      // 设置中文字体
      BaseFont bfChinese = BaseFont
          .createFont("STSongStd-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
      // 标题字体风格
      Font titleFont = new Font(bfChinese, 22, Font.BOLD);
      // 正文字体风格
      Font contextFont = new Font(bfChinese, 14, Font.NORMAL);
      // 参数字体风格
      Font paramFont = new Font(bfChinese, 14, Font.UNDERLINE);
      Paragraph title = new Paragraph("合作作品创作声明", titleFont);
      // 设置标题格式对齐方式
      title.setAlignment(Element.ALIGN_CENTER);
      title.setFont(titleFont);
      title.setLeading(15f);
      document.add(title);
      // 特殊字段设置
      // 作品名称
      Chunk workname = new Chunk(copyRightWorks.getWorksFullName(), paramFont);

      Chunk currentdate = new Chunk(DateUtil.formatDate(new Date()), paramFont);

      // 年月日

      // 段落1
      Paragraph para1 = new Paragraph();
      para1.setLeading(20f);
      para1.setAlignment(Element.ALIGN_LEFT);
      para1.setFont(contextFont);
      para1.setSpacingBefore(3);
      para1.setFirstLineIndent(30);
      para1.add("作品《" + workname + "》是");
      if (!StringUtil.isEmpty(copyRightWorks.getAuthor())) {
        String[] authorArray = copyRightWorks.getAuthor().split("\\$");
        for (int index = 0; index < authorArray.length; index++) {
          Chunk owner = new Chunk(authorArray[index], paramFont);
          para1.add(owner);
          if (index < (authorArray.length - 1)) {
            para1.add("与");
          }
        }
      }
      para1.add("联合创作的作品，属于合作作品，《 ");
      para1.add(workname);
      para1.add("》作品著作权归");
      if (!StringUtil.isEmpty(copyRightWorks.getAuthor())) {
        String[] authorArray = copyRightWorks.getAuthor().split("\\$");
        for (int index = 0; index < authorArray.length; index++) {
          Chunk owner = new Chunk(authorArray[index], paramFont);
          para1.add(owner);
          if (index < (authorArray.length - 1)) {
            para1.add("与");
          }
        }
      }
      para1.add("共同享有。");
      document.add(new Paragraph("\n"));
      document.add(para1);

      // 段落3
      Paragraph para3 = new Paragraph();
      para3.setAlignment(Element.ALIGN_RIGHT);
      para3.setFont(contextFont);
      para3.setSpacingBefore(20);
      para3.setSpacingAfter(0);
      para3.setIndentationRight(10);
      para3.setLeading(10f);
      para3.add("签章：");
      para3.add(copyRightWorks.getAuthor().replaceAll("\\$", ","));
      document.add(para3);

      // 段落7
      Paragraph para7 = new Paragraph("\n");
      para7.setFont(contextFont);
      para7.setSpacingBefore(20);
      para7.setIndentationRight(10);
      para7.setAlignment(Element.ALIGN_RIGHT);
      para7.setLeading(10f);
      para7.add("日期：");
      para7.add(currentdate);
      document.add(para7);

      document.close();

    } catch (Exception e) {
      logger.error("生成合作创作声明失败", e);
      throw new BizException("生成合作创作声明文件失败");
    }
    uploadToOSS(file);
  }

}
